home *** CD-ROM | disk | FTP | other *** search
/ Merciful 5 / Merciful - Disc 5.iso / software / p / pcqpascalv1.2d.lha / Examples2 / Reset / Reset_WB3.0.p < prev    next >
Text File  |  1997-05-06  |  4KB  |  162 lines

  1. Program Reset;
  2.  
  3. {    Reset V1.0
  4.      © 1993 by Andreas Tetzl.
  5.      Dieses Programm ist Freeware.
  6.  
  7.  Die Datei TrapHandler.o muß zum Objektcode dazugelinkt werden. }
  8.  
  9. {$I "Include:Intuition/Intuition.i"}
  10. {$I "Include:Graphics/Graphics.i"}
  11. {$I "Include:Graphics/Pens.i"}
  12. {$I "Include:Exec/ExecBase.i"}
  13. {$I "Include:Exec/Interrupts.i"}
  14. {$I "Include:Exec/Ports.i"}
  15. {$I "Include:Exec/Tasks.i"}
  16. {$I "Include:Exec/Memory.i"}
  17. {$I "Include:Exec/Interrupts.i"}
  18. {$I "Include:Exec/Devices.i"}
  19. {$I "Include:Utils/IOUtils.i"}
  20. {$I "Include:Devices/KeyBoard.i"}
  21. {$I "Include:Exec/IO.i"}
  22. {$I "Include:Libraries/DOS.i"}
  23. {$I "Include:Utils/StringLib.i"}
  24.  
  25. Const  StdIn = NIL;       { Damit auf der WB kein Window geöffnet wird }
  26.       StdOut = StdIn;
  27.  
  28. Type MyData = Record
  29.       MyTask : TaskPtr;
  30.       MySignal : Integer;
  31.      end;
  32.      
  33.  
  34. VAR  KeyIO             : IOStdReqPtr;
  35.      KeyMP             : MsgPortPtr;
  36.      KeyHandler        : InterruptPtr;
  37.      MyDataStuff       : MyData;
  38.      MySignal, OpenDev : Integer;
  39.      SysBase           : ExecBasePtr;
  40.      
  41. Procedure ColdReboot;
  42. Begin
  43. {$A
  44.     move.l    $4,a6
  45.     jmp        -726(a6)        ; ColdReboot Exec.lib V37+
  46. }
  47. end;
  48.  
  49. Procedure Reset;
  50. Const
  51.  
  52.    Topaz : TextAttr = ("topaz.font",8,FS_NORMAL,FPB_ROMFONT);
  53.         
  54.    WarmGadgetText : IntuiText = (1,0,JAM1,3,3,@Topaz,"WarmStart",NIL);
  55.    KaltGadgetText : IntuiText = (1,0,JAM1,3,3,@Topaz,"KaltStart",NIL);
  56.  
  57.    ResetText : IntuiText=(1,0,JAM1,16,10,@Topaz,"Reset in    Sekunden",NIL);
  58.    Zeit      : IntuiText=(1,0,JAM2,119,27,@Topaz,"  ",NIL);
  59.  
  60. VAR  Win : WindowPtr;
  61.      RP : RastPortPtr;
  62.     Msg, MsgCpy : IntuiMessagePtr;
  63.     Time, i : Short;
  64.     Gad : GadgetPtr;
  65.  
  66. Begin
  67.   Win:=BuildSysRequest(NIL,adr(ResetText),adr(WarmGadgetText),adr(KaltGadgetText),GADGETUP_f,200,40);
  68.   SetWindowTitles(Win,"Reset V1.0 by Andreas Tetzl",NIL);
  69.   
  70.   Time:=10;
  71.   Repeat
  72.    i:=IntToStr(Zeit.IText,Time);
  73.    StrCat(Zeit.IText," ");
  74.    PrintIText(Win^.RPort,adr(Zeit),0,0);
  75.    For i:=1 to 5 do
  76.     Begin
  77.      Delay(10);
  78.      Msg:=IntuiMessagePtr(GetMsg(Win^.UserPort));
  79.      If Msg<>NIL then
  80.       Begin
  81.        Gad:=Msg^.Iaddress;
  82.        If Gad^.GadgetID=1 then   { Warmstart }
  83.         ColdReboot;    { Reset }
  84.        If Gad^.GadgetID=0 then   { Kaltstart }
  85.         Begin
  86.          Forbid;                     { Damit sich Viren nicht neu installieren können }
  87.          SysBase^.ColdCapture:=NIL;  { Resetvektoren löschen }
  88.          SysBase^.CoolCapture:=NIL;
  89.          SysBase^.WarmCapture:=NIL;
  90.          SysBase^.KickMemPtr:=NIL;
  91.          SysBase^.KickTagPtr:=NIL;
  92.          SysBase^.KickCheckSum:=NIL;
  93.          ColdReboot;         { Reset }
  94.         end;         
  95.       end;
  96.     end;
  97.    Dec(Time);
  98.   Until Time=0;   { Nach Zehn Sekunden wird automatisch ein Reset ausgeführt }
  99. end;
  100.  
  101. Procedure Meldung;
  102. VAR  Con : FileHandle;
  103.     z : Integer;
  104. Begin
  105.   Con:=DOSOpen("con:128/100/320/50/Reset",MODE_NEWFILE);
  106.   If Con=NIL then Return;
  107.   z:=DOSWrite(Con,"Reset V1.0 von Andreas Tetzl installiert\n",42);
  108.   Delay(100);
  109.   DOSClose(Con);
  110. end;
  111.  
  112. Procedure ResetHandler;
  113. External;
  114.  
  115. Function WaitForSignal(MySignal : Integer) : Short;
  116. Begin
  117.   WaitForSignal:=Wait(MySignal);
  118. end;
  119.  
  120. Procedure CleanExit;
  121. Begin
  122.   If OpenDev=0 then CloseDevice(KeyIO);
  123.   If KeyIO<>NIL then DeleteStdIO(KeyIO);
  124.   If KeyMP<>NIL then DeletePort(KeyMP);
  125.   If MySignal<>-1 then FreeSignal(MySignal);
  126.   DisplayBeep(NIL);
  127. end;
  128.  
  129. Begin
  130.   {$A    move.l    $4,_SysBase   }
  131.   OpenDev:=1;
  132.  
  133.   New(KeyHandler);
  134.   MySignal:=AllocSignal(-1);
  135.   If MySignal=-1 then CleanExit;
  136.  
  137.   MyDataStuff.MyTask:=FindTask(NIL);
  138.   MyDataStuff.MySignal:=1 SHL MySignal;
  139.   KeyMP:=CreatePort(NIL,0);
  140.   If KeyMP=NIL then CleanExit;
  141.  
  142.   KeyIO:=CreateStdIO(KeyMP);
  143.   If KeyIO=NIL then CleanExit;
  144.   
  145.   OpenDev:=OpenDevice("keyboard.device",0,KeyIO,0);
  146.   If OpenDev<>0 then CleanExit;
  147.   
  148.  
  149.   KeyHandler^.is_Code:=adr(ResetHandler);
  150.   KeyHandler^.is_Data:=adr(MyDataStuff);
  151.   Keyhandler^.is_Node.ln_Pri:=16;
  152.   KeyHandler^.is_Node.ln_name:="Reset";
  153.   KeyIO^.io_Data:=KeyHandler;
  154.   KeyIO^.io_Command:=KBD_ADDRESETHANDLER;            { ResetHandler installieren }
  155.   If DoIO(KeyIO)<>0 then CleanExit;
  156.   Meldung;
  157.   If WaitForSignal(MyDataStuff.MySignal)=0 then      { auf Reset warten }
  158.    Begin
  159.     Reset;
  160.    end;
  161. end.
  162.